package com.magicsoft.app.adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;

public class BankListAdapter  extends BaseAdapter {
	List<HashMap<String, String>> data;
	LayoutInflater inflater;
	
	public BankListAdapter(Context context,
			List<HashMap<String, String>> data) {
		inflater = LayoutInflater.from(context);
		this.data = data;
	}
	
	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(
					R.layout.textview_list_item, null);
			holder.tvBank = (TextView) convertView
					.findViewById(android.R.id.text1);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		HashMap<String, String> map = data.get(position);
		String bank = map.get("name");
		
		if (bank != null) {
			holder.tvBank.setText(bank);
		} else {
			holder.tvBank.setText("");
		}
		
		return convertView;
	}
	
	private final class ViewHolder {
		String id;
		TextView tvBank;
	}
}